﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Myotragus.Data.Registration
{
	public static class ServicesImplementation
	{
		public static IServicesImplementationCollection FromAssembly(Assembly asm)
		{
			return FromThese(asm.GetTypes());
		}

		public static IServicesImplementationCollection FromAssemblyContaining(Type type)
		{
			return FromAssembly(type.Assembly);
		}

		public static IServicesImplementationCollection FromAssemblyContaining<TType>()
		{
			return FromAssembly(typeof(TType).Assembly);
		}

		public static IServicesImplementationCollection FromThese(IEnumerable<Type> types)
		{
			return new ServicesImplementationCollection
			{
				Actual = types.Where(x => x.IsClass && !x.IsAbstract)
			};
		}

		public static IServicesImplementationCollection FromThese(params Type[] types)
		{
			return FromThese((IEnumerable<Type>)types);
		}
	}
}